﻿using System;
using System.Collections.Concurrent;

namespace HB.MsgBusItem
{
    /// <summary>
    /// topic锁定类
    /// </summary>
    internal class TopicLocker
    {
        static TopicLocker()
        {
            dic = new ConcurrentDictionary<string, LockItem>();
        }
        public class LockItem
        {
            Guid UId = Guid.NewGuid();
        }
        /// <summary>
        /// 为每个topic提供锁
        /// </summary>
        static ConcurrentDictionary<string, LockItem> dic = null;
        public static LockItem GetLock(string topic)
        {
            if (dic.ContainsKey(topic)) { return dic[topic]; }
            else
            {
                dic.TryAdd(topic, new LockItem());
                return dic[topic];
            }
        }
    }
}
